package com.qqtech.qquan.circle.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.circle.model.CircleCategory;
import com.qqtech.qquan.circle.model.CircleCategoryQuery;
import com.qqtech.qquan.circle.model.CircleCategoryVo;
import com.qqtech.qquan.circle.service.CircleCategoryService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/circle/category")
public class CircleCategoryController extends BaseWebController<CircleCategory, CircleCategoryQuery> {
	@Resource
	private CircleCategoryService circleCategoryService;
    
	@Override
	protected BaseService<CircleCategory> getBaseService() {
		return circleCategoryService;
	}
	
	/**
	 * 获取一级分类
	 * @return
	 */
	@RequestMapping(value = "/levle1List")
	@ResponseBody
	public Result findParent() {
		Result result = new Result();
		List<CircleCategoryVo> list = circleCategoryService.queryLevle1List();
		result.put("levle1List", list);
		return result;
	}

	/**
	 * 获取子分类
	 * @param parentId
	 *            父级id
	 * @return
	 */
	@RequestMapping(value = "/getChildrenList")
	@ResponseBody
	public Result getChildrenList(@RequestBody CircleCategoryQuery circleCategoryQuery) {
		Result result = new Result();
		Integer parentId = circleCategoryQuery.getParentId();
		if(parentId==null){
			result.addErr("父级id为空!");
			return result;
		}
		List<CircleCategoryVo> list = circleCategoryService.queryChildrenList(parentId);
		result.put("childrenList", list);
		CircleCategoryVo parent = circleCategoryService.getById(parentId);
		result.put("parentName", parent==null?"":parent.getName());
		return result;
	}
}
